import cv2
import numpy as np

img=cv2.imread(r'C:\Users\ASUS\Desktop\1.jpg') #读取图片
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#转灰度
gray=np.float32(gray)#因为k取值在0.04到0.06之间要先转化成浮点数。
harris=cv2.cornerHarris(gray,2,3,0.04)
harrisarris=cv2.dilate(harris,None)
img[harris>0.01*harris.max()]=[0,0,255]

cv2.imshow('harris',img)

cv2.waitKey()
cv2.destroyAllWindows()
